#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    bool isValid(string s) {
        stack<char> st;
        for (auto e : s)
        {
            if (e == '(' || e == '[' || e == '{')
                st.push(e);
            else
            {
                if (st.empty() == 1)
                    return false;
                if (e == ')' && st.top() == '(' || e == ']' && st.top() == '[' || e == '}' && st.top() == '{')
                    st.pop();
                else
                    return false;
            }
        }
        return st.empty();
    }
};

class Solution {
public:
    string removeDuplicates(string s) {
        stack<char> st;
        for (auto e : s)
        {
            if (st.empty() || e != st.top())
                st.push(e);
            else
                st.pop();
        }
        string ret;
        while (!st.empty())
        {
            ret += st.top();
            st.pop();
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
};

class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        stack<int> s;
        for (int i = 0; i < tokens.size(); i++)
        {
            if (tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/")
            {
                int second = s.top();
                s.pop();
                int first = s.top();
                s.pop();
                if (tokens[i] == "+") { s.push(first + second); }
                if (tokens[i] == "-") { s.push(first - second); }
                if (tokens[i] == "*") { s.push(first * second); }
                if (tokens[i] == "/") { s.push(first / second); }
            }
            else
                s.push(stoi(tokens[i]));
        }
        return s.top();
    }
};